/*
 *
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','courseAnalyseList');

/*controller部分*/


//定义父controller，主要用于controller之间传递信息
authApp.controller("fcontroller",function($scope,$http){
})


//主要操作controller
authApp.controller("opinionListcontroller",function($scope,$http, $cookies){
    //针对此页面需要的参数 should edit
    $scope.isAddM=true;
    $scope.accounttype = $cookies.get('accounttype')
    //**********主体方法
    var queryMainApi=apis.queryCAsByExpert;//！！！should edit
    $scope.queryMain=function(){
        $http({
            method:'post',
            url:queryMainApi,
            data:{},
        }).success(function(response){
            if(response.code=="000000"){
                $scope.queryMainApiCallBack(response);
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("网络出现故障，请确认网络是否连接");
        })
    }

    $scope.queryMain();

    /*下面为自已编辑部分*/

    //调用主接口成功之后的处理方法
    $scope.queryMainApiCallBack=function(response){
        $scope.list=response.data;
    }

    //添加学校
    $scope.SchoolLists=function(){
        $http({
            method:'post',
            url:apis.querySchoolByExpert,
            data:{},
        }).success(function(response){
            if(response.code=="000000"){
                $scope.schoollists = response.data;
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("网络出现故障，请确认网络是否连接");
        })
    }

    $scope.addSchoolList=function(){
        $scope.isAddM=false;
        $scope.SchoolLists();
    }

    $scope.cancelAddM=function(){
        $scope.isAddM=true;
        $scope.number="";
        $scope.schoolName="";
    }

    $scope.addFirstZ=function(){
        if(window.confirm("是否确认添加？")) {
            $http({
                method: 'post',
                url: apis.addCAMap,
                data: {'schoolId': $scope.schoolId, 'sign': $scope.number},
            }).success(function (response) {
                if (response.code == "000000") {
                    $scope.isAddM=true;
                    $scope.number="";
                    $scope.schoolName="";
                    alert("添加成功！");
                    $scope.queryMain();
                } else {
                    alert(response.errorMsg);
                }
            }).error(function () {
                alert("网络出现故障，请确认网络是否连接");
            })
        }
    }

    $scope.turnTo=function(schoolId,schoolName,sign,state, f, pid){
        location.href="table2.html?schoolId="+schoolId+"&schoolName="+encodeURIComponent(schoolName)+"&sign="+sign+"&state="+state+'&f='+f+'&pid='+pid;
    }
    
    $scope.download=function(schoolId,sign){
        location.href=apis.downCourseAnalyse+"?schoolId="+schoolId+"&sign="+sign;
    }
    $scope.delete = function(pid) {
        if(window.confirm("是否确定删除？")){
            $http({
                method:'post',
                url:apis.deleteCourseAnalyse,
                data:{'pid': pid},
            }).success(function(response){
                if(response.code=="000000"){
                    $scope.queryMain();
                }else{
                    alert(response.errorMsg);
                }
            }).error(function(){
                alert("服务器打瞌睡了，请稍等！");
            }) 
        }
    }
    function toUnicode(str)
    {
        return escape(str).replace(/%/g,"\\").toLowerCase();
    }
})


